<template>
	<view class="content" :style="'background: url('+ c_imgPath + 'mine/indexBg.png'+ ') repeat-y 0 0 / 100% auto;'">
		<view class="header">
			<view class="qiehuan">
				<view @click="getlist(i+1)" v-for="(v,i) in arr" :key="i">
					<view :class="show==i+1?'xzs':'wzs'">{{v}}</view>
					<view class="qiehuan_line" v-if="show==i+1">
						<image :src="c_imgPath+'mine/text_bom.png'"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 内容 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
			<view class="coupon" v-for="(item,index) in aixuanArr" :key="index"
				:style="'background: url('+ c_imgPath + 'mine/'+ item.title +'_bg.png'+ ') no-repeat 0 0 / 100% 100%;'">
				<view class="coupon_item">
					<view class="coupon_item_1">
						<view class="coupon_item_l_title"><text>{{item.title}}级</text>宝藏券</view>
						<view class="coupon_item_1_text">可随机开出<text>{{item.min}}-{{item.max}}</text>赏币</view>
					</view>
					<view v-if="show==1" class="coupon_r"
						:style="'background: url('+ c_imgPath +'mine/share.png'+ ') no-repeat 0 0 / 100% 100%;'">
						<button open-type="share" :data-id="item.id" :data-img="item.share_imgurl"
							style="width: 100%;height: 100%;">分享</button>
					</view>
					<!-- -->
					<view class="coupon_r" v-else @click="kaiquan(item.id)"
						:style="'background: url('+c_imgPath + 'mine/kaiqi.png'+ ') no-repeat 0 0 / 100% 100%;'">
						开启
					</view>
				</view>
			</view>
		</mescroll-body>

		<!-- 奖品弹窗 -->
		<uni-popup ref="pop_show" type="center">
			<view class="mengban"></view>
			<view class="pop_jp "
				:style="'background: url('+c_imgPath + 'mine/coupon/kaiquan_bg.png'+ ') no-repeat 0 0 / 100% 100%;'">
				<view>获得{{num}}个赏币</view>
				<view class="pop_btn" @click="$refs.pop_show.close()">已放入您的账号,知道了</view>
			</view>
		</uni-popup>


	</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				z_imgPath: this.$z_img,
				c_imgPath: 'https://qt.yhemall.com/',
				cc_imgPath: '/static/',
				arr: ['我的券', '参与中'],
				show: 1,

				downOption: {
					auto: false
				},
				aixuanArr: [],

				// 开券获得币的数量
				num: '',

			}
		},
		onLoad(e) {
			if (e && e.show == 2) {
				this.show = 2
			}
		},
		onShareAppMessage(e) {
			console.log(e)
			return {
				title: "点击领取欧气券吧~",
				imageUrl: e.target.dataset.img,
				path: "/pages/user/index?coupon_id=" + e.target.dataset.id + '&pid=' + uni.getStorageSync('userinfo').ID +
					'&from=' + uni.getStorageSync('userinfo').from
			};
		},
		methods: {
			kaiquan(e) {
				let that = this;
				that.num = '6'
				that.$refs.pop_show.open();
				return
				that.req({
					url: 'coupon_open',
					data: {
						coupon_id: e
					},
					success(res) {
						if (res.status == 1) {
							that.num = res.data
							that.$refs.pop_show.open()
							that.loadData(1)

						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 1500,
								success() {
									setTimeout(() => {
										that.loadData(1)
									})
								}
							})
						}
					}
				})
			},
			getlist(v) {
				this.show = v;
				this.aixuanArr = []
				this.mescroll.resetUpScroll()
			},
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				this.loadData(page.num);
			},
			loadData(pageNo) {
				let that = this;
				that.req({
					url: 'coupon_list',
					Loading: true,
					data: {
						page: pageNo,
						type: that.show
					},
					success(res) {

						that.mescroll.endByPage(res.data.data.length, res.data.last_page);
						if (pageNo == 1) {
							that.aixuanArr = res.data.data;
						} else {
							that.aixuanArr = that.aixuanArr.concat(res.data.data);
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.pop_btn {
		width: 380rpx;
		height: 60rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 32rpx;
		color: #FFFFFF;
		position: relative;
		top: 372rpx;
		left: 0;
		right: 0;
		margin: auto;
		border-bottom: 1px solid #FFFFFF;
	}

	.pop_jp>view:nth-of-type(1) {
		padding-top: 104rpx;
		box-sizing: border-box;
		font-size: 30rpx;
		color: #BC9FFF;
	}

	.pop_jp {
		width: 608rpx;
		height: 658rpx;
		position: relative;
		text-align: center;
		z-index: 99;
	}

	.mengban {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 9;
		background: rgba(0, 0, 0, 0.6);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	button::after {
		border: none;
	}

	button {
		background-color: transparent;
		padding-left: 0;
		padding-right: 0;
		line-height: inherit;
		border-radius: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.sixiao {
		position: absolute;
		width: 92rpx;
		height: 69rpx;
		right: 20rpx;
		bottom: 20rpx;
	}

	.sy_btn {
		background: #96FFFE !important;
	}

	.coupon_r {
		width: 100rpx;
		height: 48rpx;
		margin-top: 10rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 28rpx;
		line-height: 48rpx;
		margin-right: 30rpx;
	}

	.coupon_item_1 {
		font-size: 28rpx;
		color: #FFFFFF;
		box-sizing: border-box;
		margin-left: 152rpx;

		.coupon_item_l_title {
			font-size: 32rpx;
			font-weight: bold;
			background: linear-gradient(0deg, #AB88D2 0.78125%, #FFFFFF 100%);
			-webkit-background-clip: text;
			-webkit-text-fill-color: transparent;
		}

		.coupon_item_l_text {
			font-size: 28rpx;
			margin-top: 20rpx;
		}
	}

	.coupon_item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 42rpx 0 30rpx;
		box-sizing: border-box;
		width: 690rpx;
		height: 172rpx;
		/* background: url(../../static/mine/A_bg.png) no-repeat; */
		/* background-size: 100% 100%; */
		margin-top: 24rpx;
		position: relative;
	}

	.coupon {
		width: 690rpx;
		height: 163rpx;
		margin: 50rpx auto;
		padding-top: 30rpx;
		/* background: #11141D; */
		/* box-shadow: 0px 0px 10rpx 0px rgba(150, 255, 254, 0.7); */
		padding: 0 30rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
	}


	.qiehuan {
		display: flex;
		justify-content: space-between;
		margin-top: 16rpx;
		width: 300rpx;
	}

	.qiehuan_line {}

	.qiehuan_line>image {
		width: 94rpx;
		height: 24rpx;
	}

	.qiehuan>view {
		flex: 1;
		text-align: center;
	}

	.wzs {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #9E99E3;
	}

	.xzs {
		font-size: 32rpx;
		background: linear-gradient(0deg, #B75AFF 0%, #E7CBFF 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		font-weight: bold;
	}


	.header {
		width: 750rpx;
		/* height: 176rpx; */
		padding-bottom: 10rpx;
		background: #09081C;
		font-size: 28rpx;
		color: #333333;
		box-sizing: border-box;
		position: fixed;
		/* #ifdef MP */
		top: 0;
		/* #endif */
		/* #ifndef MP */
		top: 88rpx;
		/* #endif */
		z-index: 15;
	}

	.content {
		width: 100vw;
		min-height: 100vh;
		padding-top: 88rpx;
		box-sizing: border-box;
	}
</style>